package com.meng.common.utils;

import java.io.Serializable;

/**
 * 响应类
 *
 * @author hufx
 * @version 1.0
 * @date 2018年1月10日下午5:39:40
 */
public class Msg<T> implements Serializable {

    private static final long serialVersionUID = -6888051142661096743L;

    private boolean success; // 是否成功

    private String msg; // 提示信息

    private T obj; // 返回对象

    private String number;// 返回代码

    public Msg() {
        this.success = true;
        this.msg = "成功!";
    }

    public static Msg sucess() {
        return new Msg();
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getObj() {
        return obj;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public final String getNumber() {
        return number;
    }

    public final void setNumber(String number) {
        this.number = number;
    }

    @Override
    public String toString() {
        return "Msg [success=" + success + ", msg=" + msg + ", obj=" + obj + ", number=" + number + "]";
    }

    /**
     * 功能描述:失败信息
     *
     * @param: message:失败消息
     * @return: Msg
     * @auther: yfl
     * @date: 2018/12/24 16:45
     */
    public static <T>Msg<T> fail(String message) {
        Msg<T> msg = new Msg<>();
        msg.setSuccess(false);
        msg.setMsg(message);
        return msg;
    }
    /**
     * 功能描述:失败信息
     *
     * @param: message:失败消息
     * @return: Msg
     * @auther: yfl
     * @date: 2018/12/24 16:45
     */
    public static <T>Msg<T> fail(String message,String number) {
        Msg<T> msg = new Msg<>();
        msg.setSuccess(false);
        msg.setMsg(message);
        msg.setNumber(number);
        return msg;
    }
    /**
     * 功能描述: 成功消息
     *
     * @param:
     * @return: successObj:成功对象
     * @auther: yfl
     * @date: 2018/12/24 16:45
     */
    public static <T>Msg<T> sucess(T successObj) {
        return sucess("成功", successObj);
    }

    /**
     * 功能描述: 成功消息
     *
     * @param: successMessage:成功消息,successObj:成功对象
     * @return:
     * @auther: yfl
     * @date: 2018/12/24 16:46
     */
    public static <T>Msg<T> sucess(String successMessage, T successObj) {
        Msg<T> msg = new Msg<>();
        msg.setObj(successObj);
        msg.setMsg(successMessage);
        msg.setSuccess(true);
        return msg;
    }

    /**
     * 功能描述: 成功消息
     *
     * @param: successMessage:成功消息,successObj:成功对象 ,number:编码数值
     * @return:
     * @auther: yfl
     * @date: 2018/12/24 16:46
     */
    public static <T>Msg<T> sucess(String successMessage, T successObj, String number) {
        Msg<T> msg = new Msg<>();
        msg.setObj(successObj);
        msg.setMsg(successMessage);
        msg.setSuccess(true);
        msg.setNumber(number);
        return msg;
    }
}
